<!--
 * @Author: pjji
 * @describe: 待审核 Search表单 -- 业务耦合型组件
 * @LastEditTime: 2020-11-29 16:36:54
-->
<template>
  <div class="search">
    <!-- 查询表单 -->
    <el-form
      :model="searchForm"
      :rules="searchFormRules"
      ref="searchForm"
      label-width="80px"
      class="searchForm mt10"
    >
      <!-- row1 -->
      <el-row :gutter="24">
        <el-col :span="5">
          <el-form-item label="产业">
            <el-select
              v-model="searchForm.industry"
              class="a_w"
              size="small"
              clearable
              placeholder="请选择"
            >
              <el-option
                v-for="item in industryTypeArr"
                :key="item.code"
                :label="item.name"
                :value="item.code"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="5">
          <el-form-item label="地区">
            <el-select
              v-model="searchForm.taxPlace"
              class="a_w"
              size="small"
              clearable
              placeholder="请选择"
            >
              <el-option
                v-for="item in taxPlaceArr"
                :key="item.code"
                :label="item.name"
                :value="item.code"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="10">
          <el-form-item label="时间">
            <el-date-picker
              v-model="updateTime"
              size="small"
              class="a_w"
              type="daterange"
              value-format="yyyy-MM-dd"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              :picker-options="pickerOptions"
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <div class="f-tar f-push-5-t">
            <el-button type="primary" class="search-btn" size="small" @click="search($event)"
              >Search</el-button
            >
          </div>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>

<script>
import { mapState } from "vuex";
import _ from "lodash";
import common from "@/mixins/common"; //公共函数
export default {
  name: "search",
  mixins: [common],
  props: {
    searchForm: {
      type: Object,
      default: () => {
        return {};
      },
    },
    // 填写规则
    searchFormRules: {
      type: Object,
      default: () => {
        return {};
      },
    },

    pickerOptions: {
      type: Object,
      default: () => {
        return {};
      },
    },
    //纳税地
    taxPlaceArr: {
      type: Array,
      default: () => [],
    },
  },
  data() {
    return {
      updateTime: [], //审核时间

      //产业
      industryTypeArr: [
        {
          code: 1,
          name: "高新产业",
        },
        {
          code: 2,
          name: "非高新产业",
        },
      ],
    };
  },
  computed: {
    _DICTAPI() {
      return this.$api.common;
    },

    ...mapState({
      defaultTaxPlace: (state) => state.defaultTaxPlace,
    }),
  },
  methods: {
    //查询
    search(flag) {
      this.$refs["searchForm"].validate((valid) => {
        if (valid) {
          // 查询时间
          this.searchForm.updateStartTime = this.updateTime[0] || "";
          this.searchForm.updateEndTime = this.updateTime[1] || "";
          this.$emit("searchFun");
        }
      });
    },
    // 重置
    reset() {
      this.$nextTick(() => {
        this.$refs["searchForm"].resetFields();
      });
    },
    // 获取列表
    async querySearchAsync(queryString, cb) {
      const { data, flag } = await this.$api
        .companyList({
          taxPlace: this.searchForm.taxPlace,
          name: queryString,
        })
        .catch((err) => {
          cb([{ value: "暂无数据", code: null }]);
        });
      if (!flag) {
        cb([{ value: "暂无数据", code: null }]);
        return;
      }
      const result = data.map((item) => {
        return {
          value: item.company,
          code: item.companyCode,
        };
      });
      result.length ? cb(result) : cb([{ value: "暂无数据", code: null }]);
    },
    // 筛选条件
    handleSelect(item) {
      if (!item.code) {
        this.searchForm.company = "";
        return;
      }
    },
  },
  mounted() {},
};
</script>

<style lang="scss" scoped>
.search {
    border-bottom: 1px dashed #ddd;
    margin-bottom: 10px;
  .a_w {
    width: 100%;
  }
  :deep(.el-button.search-btn) {
    background: linear-gradient(to right, #2ab1e8, #35d1ce);
  }
}
</style>
